package logic

import (
	"box-fresh-api/models/mysql"
	"context"

	"box-fresh-api/boxrpc/boxrpc"
	"box-fresh-api/boxrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
	"gorm.io/gorm"
)

type BrandAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBrandAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BrandAddLogic {
	return &BrandAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BrandAddLogic) BrandAdd(in *boxrpc.BrandAddRequest) (*boxrpc.BrandAddResponse, error) {
	// todo: add your logic here and delete this line
	brands := mysql.Brand{
		Model:     gorm.Model{},
		BrandName: in.BrandName,
	}
	err := brands.BrandAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &boxrpc.BrandAddResponse{
		BrandId: int64(brands.ID),
	}, nil
}
